package com.woniu.controller;
import com.woniu.entity.ChargingCard;
import com.woniu.service.ChargingCardService;
import com.woniu.util.ResponseData;
import com.woniu.util.ResponseEnum;
import com.woniu.vo.ChargingCardVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * FileName: ChargingCardController
 * Author: wujiajun
 * Date:   2025/2/15 11:41
 * Description:DOTO
 */
@RestController
@RequestMapping("/chargingCard")
public class ChargingCardController {
    @Resource
    private ChargingCardService chargingCardService;

    @GetMapping("/queryCard")
    public ResponseData<?> queryCard(
            @RequestParam(required = false) String keyword,
            @RequestParam(required = false, defaultValue = "false") boolean exact,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        List<ChargingCardVO> cardList = chargingCardService.getChargingCardList(keyword, exact, pageNum, pageSize);
        return ResponseData.ok(cardList);
    }

    @PostMapping("/add")
    public ResponseData<?> addChargingCard(@RequestBody ChargingCard chargingCard) {
        boolean success = chargingCardService.addChargingCard(chargingCard);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }

    @DeleteMapping("/{id}")
    public ResponseData<?> deleteChargingCard(@PathVariable("id") Long id) {
        boolean success = chargingCardService.deleteChargingCard(id);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }

    @PostMapping("/update")
    public ResponseData<?> updateChargingCard(@RequestBody ChargingCard chargingCard) {
        boolean success = chargingCardService.updateChargingCard(chargingCard);
        return success ? ResponseData.ok() : ResponseData.fail(ResponseEnum.FAIL);
    }
}
